home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / unix / tclUnixPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  10.0 KB  |  481 lines  |  [TEXT/CWIE]

  1. /*
  2.  * tclUnixPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because
  5.  *    of differences between systems.  It reads in UNIX-related
  6.  *    header files and sets up UNIX-related macros for Tcl's UNIX
  7.  *    core.  It should be the only file that contains #ifdefs to
  8.  *    handle different flavors of UNIX.  This file sets up the
  9.  *    union of all UNIX-related things needed by any of the Tcl
  10.  *    core files.  This file depends on configuration #defines such
  11.  *    as NO_DIRENT_H that are set up by the "configure" script.
  12.  *
  13.  *    Much of the material in this file was originally contributed
  14.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  15.  *
  16.  * Copyright (c) 1991-1994 The Regents of the University of California.
  17.  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
  18.  *
  19.  * See the file "license.terms" for information on usage and redistribution
  20.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  21.  *
  22.  * SCCS: @(#) tclUnixPort.h 1.49 97/07/30 14:11:59
  23.  */
  24.  
  25. #ifndef _TCLUNIXPORT
  26. #define _TCLUNIXPORT
  27.  
  28. #ifndef _TCLINT
  29. #   include "tclInt.h"
  30. #endif
  31. #include <errno.h>
  32. #include <fcntl.h>
  33. #ifdef HAVE_NET_ERRNO_H
  34. #   include <net/errno.h>
  35. #endif
  36. #include <pwd.h>
  37. #include <signal.h>
  38. #include <sys/param.h>
  39. #include <sys/types.h>
  40. #ifdef USE_DIRENT2_H
  41. #   include "../compat/dirent2.h"
  42. #else
  43. #   ifdef NO_DIRENT_H
  44. #    include "../compat/dirent.h"
  45. #   else
  46. #    include <dirent.h>
  47. #   endif
  48. #endif
  49. #include <sys/file.h>
  50. #ifdef HAVE_SYS_SELECT_H
  51. #   include <sys/select.h>
  52. #endif
  53. #include <sys/stat.h>
  54. #if TIME_WITH_SYS_TIME
  55. #   include <sys/time.h>
  56. #   include <time.h>
  57. #else
  58. #   if HAVE_SYS_TIME_H
  59. #       include <sys/time.h>
  60. #   else
  61. #       include <time.h>
  62. #   endif
  63. #endif
  64. #ifndef NO_SYS_WAIT_H
  65. #   include <sys/wait.h>
  66. #endif
  67. #ifdef HAVE_UNISTD_H
  68. #   include <unistd.h>
  69. #else
  70. #   include "../compat/unistd.h"
  71. #endif
  72. #ifdef    USE_FIONBIO
  73.  
  74.     /*
  75.      * Not using the Posix fcntl(...,O_NONBLOCK,...) interface, instead
  76.      * we are using ioctl(..,FIONBIO,..).
  77.      */
  78.  
  79. #   ifdef HAVE_SYS_FILIO_H
  80. #    include    <sys/filio.h>    /* For FIONBIO. */
  81. #   endif
  82.  
  83. #   ifdef HAVE_SYS_IOCTL_H
  84. #    include    <sys/ioctl.h>    /* For FIONBIO. */
  85. #   endif
  86. #endif    /* USE_FIONBIO */
  87.  
  88. /*
  89.  * Socket support stuff: This likely needs more work to parameterize for
  90.  * each system.
  91.  */
  92.  
  93. #include <sys/socket.h>        /* struct sockaddr, SOCK_STREAM, ... */
  94. #ifndef NO_UNAME
  95. #   include <sys/utsname.h>    /* uname system call. */
  96. #endif
  97. #include <netinet/in.h>        /* struct in_addr, struct sockaddr_in */
  98. #include <arpa/inet.h>        /* inet_ntoa() */
  99. #include <netdb.h>        /* gethostbyname() */
  100.  
  101. /*
  102.  * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we
  103.  * look for an alternative definition.  If no other alternative is available
  104.  * we use a reasonable guess.
  105.  */
  106.  
  107. #ifndef NO_FLOAT_H
  108. #include <float.h>
  109. #else
  110. #   ifndef NO_VALUES_H
  111. #    include <values.h>
  112. #   endif
  113. #endif
  114.  
  115. #ifndef FLT_MAX
  116. #   ifdef MAXFLOAT
  117. #    define FLT_MAX MAXFLOAT
  118. #   else
  119. #    define FLT_MAX 3.402823466E+38F
  120. #   endif
  121. #endif
  122. #ifndef FLT_MIN
  123. #   ifdef MINFLOAT
  124. #    define FLT_MIN MINFLOAT
  125. #   else
  126. #    define FLT_MIN 1.175494351E-38F
  127. #   endif
  128. #endif
  129.  
  130. /*
  131.  * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
  132.  */
  133.  
  134. #ifndef O_NONBLOCK
  135. #   define O_NONBLOCK 0x80
  136. #endif
  137.  
  138. /*
  139.  * HPUX needs the flag O_NONBLOCK to get the right non-blocking I/O
  140.  * semantics, while most other systems need O_NDELAY.  Define the
  141.  * constant NBIO_FLAG to be one of these
  142.  */
  143.  
  144. #ifdef HPUX
  145. #  define NBIO_FLAG O_NONBLOCK
  146. #else
  147. #  define NBIO_FLAG O_NDELAY
  148. #endif
  149.  
  150. /*
  151.  * The following defines denote malloc and free as the system calls
  152.  * used to allocate new memory.  These defines are only used in the
  153.  * file tclCkalloc.c.
  154.  */
  155.  
  156. #define TclpAlloc(size)        malloc(size)
  157. #define TclpFree(ptr)        free(ptr)
  158. #define TclpRealloc(ptr, size)    realloc(ptr, size)
  159.  
  160. /*
  161.  * The default platform eol translation on Unix is TCL_TRANSLATE_LF:
  162.  */
  163.  
  164. #define    TCL_PLATFORM_TRANSLATION    TCL_TRANSLATE_LF
  165.  
  166. /*
  167.  * Not all systems declare the errno variable in errno.h. so this
  168.  * file does it explicitly.  The list of system error messages also
  169.  * isn't generally declared in a header file anywhere.
  170.  */
  171.  
  172. extern int errno;
  173.  
  174. /*
  175.  * The type of the status returned by wait varies from UNIX system
  176.  * to UNIX system.  The macro below defines it:
  177.  */
  178.  
  179. #ifdef _AIX
  180. #   define WAIT_STATUS_TYPE pid_t
  181. #else
  182. #ifndef NO_UNION_WAIT
  183. #   define WAIT_STATUS_TYPE union wait
  184. #else
  185. #   define WAIT_STATUS_TYPE int
  186. #endif
  187. #endif
  188.  
  189. /*
  190.  * Supply definitions for macros to query wait status, if not already
  191.  * defined in header files above.
  192.  */
  193.  
  194. #ifndef WIFEXITED
  195. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  196. #endif
  197.  
  198. #ifndef WEXITSTATUS
  199. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  200. #endif
  201.  
  202. #ifndef WIFSIGNALED
  203. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  204. #endif
  205.  
  206. #ifndef WTERMSIG
  207. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  208. #endif
  209.  
  210. #ifndef WIFSTOPPED
  211. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  212. #endif
  213.  
  214. #ifndef WSTOPSIG
  215. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  216. #endif
  217.  
  218. /*
  219.  * Define constants for waitpid() system call if they aren't defined
  220.  * by a system header file.
  221.  */
  222.  
  223. #ifndef WNOHANG
  224. #   define WNOHANG 1
  225. #endif
  226. #ifndef WUNTRACED
  227. #   define WUNTRACED 2
  228. #endif
  229.  
  230. /*
  231.  * Supply macros for seek offsets, if they're not already provided by
  232.  * an include file.
  233.  */
  234.  
  235. #ifndef SEEK_SET
  236. #   define SEEK_SET 0
  237. #endif
  238.  
  239. #ifndef SEEK_CUR
  240. #   define SEEK_CUR 1
  241. #endif
  242.  
  243. #ifndef SEEK_END
  244. #   define SEEK_END 2
  245. #endif
  246.  
  247. /*
  248.  * The stuff below is needed by the "time" command.  If this
  249.  * system has no gettimeofday call, then must use times and the
  250.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  251.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  252.  * some might not even have HZ.
  253.  */
  254.  
  255. #ifdef NO_GETTOD
  256. #   include <sys/times.h>
  257. #   include <sys/param.h>
  258. #   ifndef CLK_TCK
  259. #       ifdef HZ
  260. #           define CLK_TCK HZ
  261. #       else
  262. #           define CLK_TCK 60
  263. #       endif
  264. #   endif
  265. #else
  266. #   ifdef HAVE_BSDGETTIMEOFDAY
  267. #    define gettimeofday BSDgettimeofday
  268. #   endif
  269. #endif
  270.  
  271. #ifdef GETTOD_NOT_DECLARED
  272. EXTERN int        gettimeofday _ANSI_ARGS_((struct timeval *tp,
  273.                 struct timezone *tzp));
  274. #endif
  275.  
  276. /*
  277.  * Define access mode constants if they aren't already defined.
  278.  */
  279.  
  280. #ifndef F_OK
  281. #    define F_OK 00
  282. #endif
  283. #ifndef X_OK
  284. #    define X_OK 01
  285. #endif
  286. #ifndef W_OK
  287. #    define W_OK 02
  288. #endif
  289. #ifndef R_OK
  290. #    define R_OK 04
  291. #endif
  292.  
  293. /*
  294.  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
  295.  * already defined.
  296.  */
  297.  
  298. #ifndef FD_CLOEXEC
  299. #   define FD_CLOEXEC 1
  300. #endif
  301.  
  302. /*
  303.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  304.  * define "lstat" to use "stat" instead.
  305.  */
  306.  
  307. #ifndef S_IFLNK
  308. #   define lstat stat
  309. #endif
  310.  
  311. /*
  312.  * Define macros to query file type bits, if they're not already
  313.  * defined.
  314.  */
  315.  
  316. #ifndef S_ISREG
  317. #   ifdef S_IFREG
  318. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  319. #   else
  320. #       define S_ISREG(m) 0
  321. #   endif
  322. # endif
  323. #ifndef S_ISDIR
  324. #   ifdef S_IFDIR
  325. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  326. #   else
  327. #       define S_ISDIR(m) 0
  328. #   endif
  329. # endif
  330. #ifndef S_ISCHR
  331. #   ifdef S_IFCHR
  332. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  333. #   else
  334. #       define S_ISCHR(m) 0
  335. #   endif
  336. # endif
  337. #ifndef S_ISBLK
  338. #   ifdef S_IFBLK
  339. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  340. #   else
  341. #       define S_ISBLK(m) 0
  342. #   endif
  343. # endif
  344. #ifndef S_ISFIFO
  345. #   ifdef S_IFIFO
  346. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  347. #   else
  348. #       define S_ISFIFO(m) 0
  349. #   endif
  350. # endif
  351. #ifndef S_ISLNK
  352. #   ifdef S_IFLNK
  353. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  354. #   else
  355. #       define S_ISLNK(m) 0
  356. #   endif
  357. # endif
  358. #ifndef S_ISSOCK
  359. #   ifdef S_IFSOCK
  360. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  361. #   else
  362. #       define S_ISSOCK(m) 0
  363. #   endif
  364. # endif
  365.  
  366. /*
  367.  * Make sure that MAXPATHLEN is defined.
  368.  */
  369.  
  370. #ifndef MAXPATHLEN
  371. #   ifdef PATH_MAX
  372. #       define MAXPATHLEN PATH_MAX
  373. #   else
  374. #       define MAXPATHLEN 2048
  375. #   endif
  376. #endif
  377.  
  378. /*
  379.  * Make sure that L_tmpnam is defined.
  380.  */
  381.  
  382. #ifndef L_tmpnam
  383. #   define L_tmpnam 100
  384. #endif
  385.  
  386. /*
  387.  * The following macro defines the type of the mask arguments to
  388.  * select:
  389.  */
  390.  
  391. #ifndef NO_FD_SET
  392. #   define SELECT_MASK fd_set
  393. #else
  394. #   ifndef _AIX
  395.     typedef long fd_mask;
  396. #   endif
  397. #   if defined(_IBMR2)
  398. #    define SELECT_MASK void
  399. #   else
  400. #    define SELECT_MASK int
  401. #   endif
  402. #endif
  403.  
  404. /*
  405.  * Define "NBBY" (number of bits per byte) if it's not already defined.
  406.  */
  407.  
  408. #ifndef NBBY
  409. #   define NBBY 8
  410. #endif
  411.  
  412. /*
  413.  * The following macro defines the number of fd_masks in an fd_set:
  414.  */
  415.  
  416. #ifndef FD_SETSIZE
  417. #   ifdef OPEN_MAX
  418. #    define FD_SETSIZE OPEN_MAX
  419. #   else
  420. #    define FD_SETSIZE 256
  421. #   endif
  422. #endif
  423. #if !defined(howmany)
  424. #   define howmany(x, y) (((x)+((y)-1))/(y))
  425. #endif
  426. #ifndef NFDBITS
  427. #   define NFDBITS NBBY*sizeof(fd_mask)
  428. #endif
  429. #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
  430.  
  431. /*
  432.  * The following implements the Unix method for exiting the process.
  433.  */
  434. #define TclPlatformExit(status) exit(status)
  435.  
  436. /*
  437.  * The following functions always succeeds under Unix.
  438.  */
  439.  
  440. #define TclHasSockets(interp) (TCL_OK)
  441. #define TclHasPipes() (1)
  442.  
  443. /*
  444.  * Variables provided by the C library:
  445.  */
  446.  
  447. #if defined(_sgi) || defined(__sgi)
  448. #define environ _environ
  449. #endif
  450. extern char **environ;
  451.  
  452. /*
  453.  * At present (12/91) not all stdlib.h implementations declare strtod.
  454.  * The declaration below is here to ensure that it's declared, so that
  455.  * the compiler won't take the default approach of assuming it returns
  456.  * an int.  There's no ANSI prototype for it because there would end
  457.  * up being too many conflicts with slightly-different prototypes.
  458.  */
  459.  
  460. extern double strtod();
  461.  
  462. /*
  463.  * The following macros define time related functions in terms of
  464.  * standard Unix routines.
  465.  */
  466.  
  467. #define TclpGetDate(t,u) ((u) ? gmtime((t)) : localtime((t)))
  468. #define TclStrftime(s,m,f,t) (strftime((s),(m),(f),(t)))
  469. #define TclpGetPid(pid)        ((unsigned long) (pid))
  470.  
  471. #define TclpReleaseFile(file)    
  472.  
  473. /*
  474.  * The following routine is only exported for testing purposes.
  475.  */
  476.  
  477. EXTERN int    TclUnixWaitForFile _ANSI_ARGS_((int fd, int mask,
  478.             int timeout));
  479.  
  480. #endif /* _TCLUNIXPORT */
  481.